<template>
  <div class="app-container">
  <el-form ref="form" :model="user" :rules="rules" label-width="80px">
    <el-form-item label="姓名" prop="realName">
      <el-input v-model="user.realName" />
    </el-form-item> 
    <el-form-item label="身份证号" prop="identityCard">
      <el-input v-model="user.identityCard"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit" v-preventReClick>确定提交</el-button>
    </el-form-item>
  </el-form>
  </div>
</template>

<script>
import { checkidentity } from "@/api/identity/check";

export default {
  props: {
    user: {
      type: Object
    }
  },
  data() {
    return {
      // 表单校验
      rules: {
        realName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        identityCard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" },
          {
            pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
            message: "请输入正确的身份证号",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    submit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          checkidentity(this.user).then(response => {
            if(response.data.authenticity==true){
              this.msgSuccess("真实");
            }else if(response.data.authenticity==false){
              this.msgError("不真实");
            }else{
              this.msgError(response.msg);
            }
          });
        }
      });
    }
  }
};
</script>
